<?php

use backend\Backend;
use yii\helpers\ArrayHelper;

// 合并common中的配置信息
$config = require Yii::getAlias('@common/config/main.php');

$globPaths = [
    '@common/modules/*/config/main.php', // 合并modules下面的主配置信息
    '@common/modules/*/config/frontend.php', // 合并modules下面的后台配置信息
    '@frontend/modules/*/config/main.php', // 合并backend下面的后台配置信息
    '@frontend/modules/*/config/frontend.php', // 合并backend下面的后台配置信息
];
foreach ($globPaths as $globPath)
{
    $files = glob(Yii::getAlias($globPath));
    foreach ($files as $file)
    {
        $config = ArrayHelper::merge(
            require $file,
            $config
        );
    }
}

$config = ArrayHelper::merge($config, [
    'id' => 'app-cms-frontend',
    'name' => '前台API',
    'basePath' => CMS_ROOT . 'frontend' . DIRECTORY_SEPARATOR,
    'runtimePath' => CMS_ROOT . 'frontend' . DIRECTORY_SEPARATOR . 'runtime',
    'controllerNamespace' => 'frontend\\controllers',
    'defaultRoute'        => 'site/index',
    'modules' => [
    ],
    'components' => [
        'request' => [
            'cookieValidationKey' => 'Djflj3*dfs',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '' => 'site/index',
            ],
        ],
    ],
    'bootstrap' => [
        'log',
    ],
    'extensions' => require(CMS_ROOT . 'vendor/yiisoft/extensions.php'),
]);

// 测试环境额外配置
if (YII_ENV_DEV)
{
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class'      => 'yii\debug\Module',
        'allowedIPs' => [
            '127.0.0.1',
            '::1',
            '192.168.33.1',
        ],
    ];
}

return $config;
